package acwing.前缀和与差分;

import java.util.Scanner;

/**
 * @description:
 * @author: qian
 * @createDate: 2021/11/5
 */
public class PrefixTwoArray {
    private static final int N = 1010;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt(); // 行
        int m = scanner.nextInt(); // 列
        int[][] a = new int[N][N];
        int[][] s = new int[N][N];
        int q = scanner.nextInt(); // q次询问
        for (int i = 1; i <= n; i++) { // 初始化
            for (int j = 1; j <= m; j++) {
                a[i][j] = scanner.nextInt();
            }
        }
        for (int i = 1; i <= n; i++) { // 全完整和
            for (int j = 1; j <= m; j++) {
                s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j]; // 求前缀合
            }
        }

        // 部分前缀和
        while(q-- != 0) {
            int x1=scanner.nextInt(), y1=scanner.nextInt(), x2=scanner.nextInt(), y2=scanner.nextInt();
            System.out.println(s[x2][y2]-s[x1-1][y2]-s[x2][y1-1]+s[x1-1][y1-1]);
        }

    }
}
